import { isArray, isString } from 'lodash';

export const mockRedisFtInfoReply = [
  'index_name',
  'idx:bicycle',
  'index_options',
  [],
  'index_definition',
  ['key_type', 'HASH', 'prefixes', ['bicycle:'], 'default_score', '1'],
  'attributes',
  [
    [
      'identifier',
      '$.brand',
      'attribute',
      'brand',
      'type',
      'TEXT',
      'WEIGHT',
      '1',
    ],
    [
      'identifier',
      '$.model',
      'attribute',
      'model',
      'type',
      'TEXT',
      'WEIGHT',
      '1',
      'NOSTEM',
    ],
    [
      'identifier',
      '$.description',
      'attribute',
      'description',
      'type',
      'TEXT',
      'WEIGHT',
      '1',
    ],
    [
      'identifier',
      '$.price',
      'attribute',
      'price',
      'type',
      'NUMERIC',
      'NOINDEX',
    ],
    [
      'identifier',
      '$.condition',
      'attribute',
      'condition',
      'type',
      'TAG',
      'SEPARATOR',
      ',',
      'CASESENSITIVE',
      'SORTABLE',
    ],
  ],
  'num_docs',
  '0',
  'max_doc_id',
  '0',
  'num_terms',
  '0',
  'num_records',
  '0',
  'inverted_sz_mb',
  '0',
  'vector_index_sz_mb',
  '0',
  'total_inverted_index_blocks',
  '0',
  'offset_vectors_sz_mb',
  '0',
  'doc_table_size_mb',
  '0',
  'sortable_values_size_mb',
  '0',
  'key_table_size_mb',
  '0',
  'records_per_doc_avg',
  '-nan',
  'bytes_per_record_avg',
  '-nan',
  'offsets_per_term_avg',
  '-nan',
  'offset_bits_per_record_avg',
  '-nan',
  'hash_indexing_failures',
  '0',
  'indexing',
  '0',
  'percent_indexed',
  '1',
  'gc_stats',
  [
    'bytes_collected',
    '0',
    'total_ms_run',
    '0',
    'total_cycles',
    '0',
    'average_cycle_time_ms',
    '-nan',
    'last_run_time_ms',
    '0',
    'gc_numeric_trees_missed',
    '0',
    'gc_blocks_denied',
    '0',
  ],
  'cursor_stats',
  [
    'global_idle',
    0,
    'global_total',
    0,
    'index_capacity',
    128,
    'index_total',
    0,
  ],
  'dialect_stats',
  ['dialect_1', '0', 'dialect_2', '0'],
];

export const mockFtInfoAnalyticsData = {
  attributes: [
    {
      type: 'TEXT',
      weight: '1',
    },
    {
      nostem: true,
      type: 'TEXT',
      weight: '1',
    },
    {
      type: 'TEXT',
      weight: '1',
    },
    {
      noindex: true,
      type: 'NUMERIC',
    },
    {
      casesensitive: true,
      sortable: true,
      type: 'TAG',
    },
  ],
  default_score: '1',
  key_type: 'HASH',
  max_doc_id: '0',
  num_docs: '0',
  num_records: '0',
  num_terms: '0',
  dialect_stats: {
    dialect_1: '0',
    dialect_2: '0',
  },
};

type InfoReplyRaw = string | number | InfoReplyRaw[];
export const replyToBuffer = (input: InfoReplyRaw[]) => {
  if (isArray(input)) {
    return input.map(replyToBuffer);
  }

  return isString(input) ? Buffer.from(input) : input;
};
